<template>
  <div class="container">
  <div class="poster">
    <img style="width: 100%;" :src="goods_img">
    <div class="back" @click="goBack"> <van-icon name="arrow-left" /></div>
    <div class="collect">
      <van-icon @click="likeThis" v-if="isLike" name="like" />
      <van-icon  @click="likeThis" v-else name="like-o" />
    </div>
  </div>
    <div class="title">
{{goodsInfo.goods_name}}
    </div>
    <div class="detail">
      {{goodsInfo.goods_description}}
    </div>
    <div class="operate">
      <div class="smallBtn">
       <div @click="goCart"> <van-icon name="cart-o" /></div>
      <div @click="goChat">  <van-icon name="chat-o" /></div>
      </div>
      <div @click="goSubmit" class="bigBtn">
        加入购物车
      </div>

    </div>

  </div>
</template>
<script>
import { Toast } from 'vant';
export default {
  name: "goodsDetail",
  data() {
    return {
         goodsInfo:{},
      goods_img:"",
      goods_id:null,
      isLike:false
    }
  },
  async created() {
    const id=this.$route.params.id
    const res=await this.$http.get('/goods/oneInfo',{
      params:{
        id:id
      }
    })
    this.goodsInfo=res.data.result.goodsInfo
    this.goods_id=res.data.result.goodsInfo.id
    this.goods_img=this.$baseUrl+res.data.result.goodsInfo.goods_img
    await this.addLookItem()
  },
  methods:{
    addLookItem(){
 console.log("添加ok")
    },
    likeThis(){
      this.isLike=!this.isLike
      if(this.isLike){
        Toast('添加收藏成功！')
      }else {
        Toast('取消收藏成功！')
      }
     },
    goBack(){
      this.$router.back()
    },
    goSubmit(){


       this.$http.post('/carts',{
         goods_id:this.goods_id
       }).then((res)=>{

         if(res.data.code==0){
           Toast('加入购物车成功！')
         }
       })
    },
    goChat(){

      this.$router.push({
        path: `/Chart/chatList/${this.goodsInfo.send_id}`
      })
    },
    goCart(){
       this.$router.push('/Cart')
    }

  }
}
</script>
<style scoped lang="less">
.container{
  position: relative;
  .poster{
    position: relative;
    .back{
      position: absolute;
      width: 30px;
      height: 30px;
      border-radius: 50%;
      background-color: rgba(0,0,0,0.4);
      text-align: center;
      font-size: 25px;
      line-height: 35px;
      left: 10px;
      top: 10px;
    }
    .collect{
      position: absolute;
      width: 40px;
      height: 40px;
      right: 15px;
      bottom: 15px;
      font-size: 35px;
    }

  }
  .title{
    background: rgba(176,224,230,0.5);
    font-weight: 600;
    min-height: 60px;
    line-height: 30px;
    padding: 5px 10px;
  }
  .detail{
    background: rgba(176,224,230,0.4);
   // text-indent: 15px;
    padding: 5px 10px;
    line-height: 25px;
  }
  .operate{
    background-color: #fff;
    position: fixed;
    bottom: 0;
    width: 100%;

display: flex;
    flex-direction: row;
    justify-content: space-between;
    height: 50px;
    .smallBtn{
      line-height: 50px;
      display: flex;
      flex-direction: row;
      justify-content: space-around;
      font-size: 30px;
      width: 40%;
    }
    .bigBtn{
     text-align: center;
      width: 50%;
      background-color:red;
      line-height: 50px;
      border-radius: 25px;

    }
  }
}
</style>
